package com.eyas.im.gui.swing.common;

import com.eyas.im.common.datasource.DataSourceUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.awt.*;
import java.io.IOException;

import static java.awt.GridBagConstraints.*;

public class CommonUtils {
    private final static Logger logger = LoggerFactory.getLogger(CommonUtils.class);
    public static void resetGridBagConstraints(GridBagConstraints gridBagConstraints) {
        assert gridBagConstraints!=null;
        gridBagConstraints.gridx = RELATIVE;
        gridBagConstraints.gridy = RELATIVE;
        gridBagConstraints.gridwidth = 1;
        gridBagConstraints.gridheight = 1;

        gridBagConstraints.weightx = 0;
        gridBagConstraints.weighty = 0;
        gridBagConstraints.anchor = CENTER;
        gridBagConstraints.fill = NONE;

        gridBagConstraints.insets = new Insets(0, 0, 0, 0);
        gridBagConstraints.ipadx = 0;
        gridBagConstraints.ipady = 0;
    }

    /**
     * 应用终止时回收资源
     */
    public static void destoryApp() {
        try {
            DataSourceUtils.INSTANCE.close();
        } catch (IOException e) {
            logger.warn("回收数据源连接池失败",e);
        }
    }
}
